package com.igeek.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.igeek.domain.Product;
import com.igeek.domain.Property;
import com.igeek.domain.Propertyvalue;
import com.igeek.mapper.PropertyMapper;
import com.igeek.mapper.PropertyvalueMapper;
import com.igeek.service.PropertyvalueService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author spike
 * @since 2022-01-12
 */
@Service
public class PropertyvalueServiceImpl extends ServiceImpl<PropertyvalueMapper, Propertyvalue> implements PropertyvalueService {
    @Autowired
    private PropertyMapper propertyMapper;
    @Autowired
    private PropertyvalueMapper propertyvalueMapper;
    @Override
    public void setPv(Product product) {
        //根据产品id设置属性
        QueryWrapper<Propertyvalue> wrapper = new QueryWrapper<>();
        wrapper.eq("pid",product.getId());
        List<Propertyvalue> propertyvalues = propertyvalueMapper.selectList(wrapper);
        for(int i=0;i<propertyvalues.size();i++ ){
            int ptid = propertyvalues.get(i).getPtid();
            Property property = propertyMapper.selectById(ptid);
            propertyvalues.get(i).setProperty(property);
        }
        product.setPvs(propertyvalues);
    }
}
